<?php
	####################################################
	# library import and object instance.              #
	####################################################
	# 커먼 인클루드
	include_once( '../common.php' );

	####################################################
	# request data($_POST AND $_GET FROM $_REQUEST)    #
	####################################################
	# REQUEST(get and post variables)
	$req = Request::clean_request($_REQUEST, FALSE);

	# GET(url variables)

	# POST(form variables)

	# Validation(special case validate)

	####################################################
	# implementation                                   #
	####################################################
	$sec->individual_access();
	$sec->run_cookie_check();

	/*/
	$updated_packages = $appm->update_packages();
	Nlog::xmp($updated_packages);
	Nlog::xmp($package_list);
	//*/

	//*/
	//if(empty($req['p1'])) $req['p1'] = 0;
	//if(empty($req['p2'])) $req['p2'] = 0;


	$pagenation_cfg1 = array(
		'uri'				=> $PHP_SELF,
		'articles_count'	=> 10,
		'req_page'			=> empty($req['p1'])? 0 : $req['p1'],
		'page_size'			=> 6,
		'articles_cnt'		=> $db->getcnts('ggo_cfg_packages_pref'),
		'style'				=> Pagenation::$style_white,
		'get'				=> 'p1'
	);
	$packages_key = $appm->get_packages_key($pagenation_cfg1['req_page'] * $pagenation_cfg1['articles_count'], $pagenation_cfg1['articles_count']);
	$pagenation1 = Pagenation::out($pagenation_cfg1);
	//Nlog::puts('packages_key',$packages_key);

	if(empty($req['sortkey'])){
		$pagenation_cfg2 = array(
			'uri'				=> $PHP_SELF,
			'articles_count'	=> 30,
			'req_page'			=> empty($req['p2']) ? 0 : $req['p2'],
			'page_size'			=> 6,
			'articles_cnt'		=> $db->getcnts('ggo_cfg_packages'),
			'style'				=> Pagenation::$style_white,
			'get'				=> 'p2'
		);
		$packages = $appm->get_packages($pagenation_cfg2['req_page'] * $pagenation_cfg2['articles_count'], $pagenation_cfg2['articles_count']);
		$pagenation2 = Pagenation::out($pagenation_cfg2);

		$req['sortkey'] = NULL;
		//Nlog::puts('packages',$packages);
	} else {
		$packages = $appm->get_packages_by_key($req['sortkey']);
		$pagenation2 = NULL;

	}

	$packages_key_all = $appm->get_packages_key(0, $db->getcnts('ggo_cfg_packages_pref'));
	//Nlog::putss($packages_key_all);

	//*/



?>
<?php
	# HTML START
	echo $html->custom_header(TITLE);
	echo $tplt->page_construct_javascript();
	echo $html->custom_js("{$JS}common.js");
	echo $html->custom_css("{$CSS}common.css");
	echo $html->custom_body();
?>
	<?php $tplt->app_head($NAVI)?>
	<?php $tplt->tiles_admin_sidebar($NAVI)?>
	<?php $tplt->tiles_admin_contents($pkname, $pname, $pdesc)?>



		<h4>패키지 키</h4>
		<?php echo NForm::open(NULL, FALSE, "keylist");?>
			<?php echo NForm::mode('modifykey')?>
			<table class="tbl" border="0" cellpadding="0" cellspacing="0">
				<colgroup>
					<col width="40" />
					<col width="40" />
					<col width="80" />
					<col width="*" />
					<col width="*" />
					<col width="*" />
					<col width="60" />
				</colgroup>
				<tr>
					<th><input type="checkbox" id="chkctr1" onclick="CheckboxControl.toggle_check_all('#chkctr1','.chk1');"/></th>
					<th>번호</th>
					<th>패키지 키</th>
					<th>패키지 이름</th>
					<th>시작할 패키지 파일명</th>
					<th>기본 파라메터</th>
					<th>정렬</th>
				</tr>
				<?php if($packages_key['has']) foreach($packages_key['res'] as $key=>$val):?>
					<tr>
						<td>
							<input type="checkbox" name="map[<?=$val['puid']?>][puid]" id="chk1_<?=$val['puid']?>" class="chk1" value="<?=$val['puid']?>" />
						</td>
						<td><?=$val['puid']?></td>
						<td>
							<?=$val['packages_key']?>
						</td>
						<td>
							<input type="text" name="map[<?=$val['puid']?>][packages_name]" maxlength="100" value="<?=$val['packages_name']?>" onfocus="CheckboxUi.focus_to_check('#chk1_<?=$val['puid']?>');" class="inp wmatch" />
						</td>
						<td>
							<input type="text" name="map[<?=$val['puid']?>][packages_init_file]" maxlength="100" value="<?=$val['packages_init_file']?>" onfocus="CheckboxUi.focus_to_check('#chk1_<?=$val['puid']?>');" class="inp wmatch" />
						</td>
						<td>
							<input type="text" name="map[<?=$val['puid']?>][param]" maxlength="100" value="<?=$val['param']?>" onfocus="CheckboxUi.focus_to_check('#chk1_<?=$val['puid']?>');" class="inp wmatch" />
						</td>
						<td>
							<a href="<?=$PHP_SELF?>?sortkey=<?=$val['packages_key']?>" target="_self">
								<span class="cbtn_s">정렬</span>&nbsp
							</a>
						</td>
					</tr>
				<?php endforeach;?>
			</table>
		<?php echo NForm::close();?>
		<div class="tblt">
			<?=$pagenation1?>
		</div>
		<div class="tblh">
			체크된 패키지 키를 : <span class="cbtn_s" onclick="$('#formx_keylist').submit();">수정</span>&nbsp;
			패키지 전체목록 보기 : <span class="cbtn_s" onclick="Mover.href('<?=$PHP_SELF?>')">보기</span>
		</div>
		<br />



		<h4>패키지</h4>
		<?php echo NForm::self(NULL, FALSE, "sortkey");?>
			<div class="tblt tar">
				패키지키로 정렬 :
				<select name="sortkey">
					<?php if($packages_key_all['has']) foreach($packages_key_all['res'] as $key=>$val):?>
						<option value="<?=$val['packages_key']?>" <?=NForm::selected($val['packages_key'], $req['sortkey'])?>>
							<?=$val['packages_name']?>(<?=$val['puid']?>-<?=$val['packages_key']?>)
						</option>
					<?php endforeach;?>
				</select>
				<span class="cbtn_s" onclick="$('#formx_sortkey').submit();">정렬</span>&nbsp;
			</div>
		<?php echo NForm::close();?>


		<?php echo NForm::open(NULL, FALSE, "list");?>
			<?php echo NForm::mode('modify')?>
			<table class="tbl" border="0" cellpadding="0" cellspacing="0">
				<colgroup>
					<col width="40" />
					<col width="40" />
					<col width="80" />
					<col width="*" />
					<col width="*" />
					<col width="*" />
					<col width="60" />
				</colgroup>
				<tr>
					<th><input type="checkbox" id="chkctr2" onclick="CheckboxControl.toggle_check_all('#chkctr2','.chk2');"/></th>
					<th>번호</th>
					<th>패키지 키</th>
					<th>패키지 파일</th>
					<th>패키지 파일 이름</th>
					<th>패키지 설명</th>
					<th>링크</th>
				</tr>
				<?php if($packages['has']) foreach($packages['res'] as $key=>$val):?>
					<tr>
						<td>
							<input type="checkbox" name="map[<?=$val['puid']?>][puid]" id="chk2_<?=$val['puid']?>" class="chk2" value="<?=$val['puid']?>" />
						</td>
						<td><?=$val['puid']?></td>
						<td>
							<?=$val['package_key']?>
						</td>
						<td>
							<?=$val['package_file']?>
						</td>
						<td>
							<input type="text" name="map[<?=$val['puid']?>][package_filename]" maxlength="100" value="<?=$val['package_filename']?>" onfocus="CheckboxUi.focus_to_check('#chk2_<?=$val['puid']?>');" class="inp wmatch" />
						</td>
						<td>
							<input type="text" name="map[<?=$val['puid']?>][package_desc]" maxlength="100" value="<?=$val['package_desc']?>" onfocus="CheckboxUi.focus_to_check('#chk2_<?=$val['puid']?>');" class="inp wmatch" />
						</td>
						<td>
							<?php if( substr($val['package_file'],-11) != 'process.php'):?>
								<a href="<?=substr($val['package_file'],0,-4)?>" target="_self">
									<span class="cbtn_s">링크</span>&nbsp;
								</a>
							<?php endif;?>
						</td>
					</tr>
				<?php endforeach;?>
			</table>
		<?php echo NForm::close();?>
		<div class="tblt">
			<?=$pagenation2?>
		</div>
		<div class="tblh">
			체크된 패키지를 : <span class="cbtn_s" onclick="$('#formx_list').submit();">수정</span>&nbsp;
			체크된 패키지를 : <span class="cbtn_s" onclick="$('#formx_list [name=mode]').val('delete'); $('#formx_list').submit();">삭제</span>&nbsp;
			패키지 리스트를 : <span class="cbtn_l" onclick="Mover.href('admin.package.update')">업데이트</span>
		</div>
		<br />




		<h4>패키지 추가</h4>
		<table class="tbl" border="0" cellpadding="0" cellspacing="0">
			<colgroup>
				<col width="40" />
				<col width="40" />
				<col width="80" />
				<col width="*" />
				<col width="*" />
				<col width="*" />
				<col width="60" />
			</colgroup>
			<tr>
				<td class="th">새로운 패키지 추가</td>
				<td>
					<?php echo NForm::open(NULL, FALSE, "create1");?>
						<?php echo NForm::mode('create')?>
							<input type="text" name="map[package_filename][]" value="" class="inp" onfocus="$(this).alphanumeric({allow:'_'})" style="ime-mode:inactive;" />.
							<input type="text" name="map[package_filename][]" value="" class="inp" onfocus="$(this).alphanumeric({allow:'_'})" style="ime-mode:inactive;" />.
							<input type="text" name="map[package_filename][]" value="" class="inp" onfocus="$(this).alphanumeric({allow:'_'})" style="ime-mode:inactive;" />
							<span class="cbtn_s" onclick="$('#formx_create1').submit();">추가</span>
					<?php echo NForm::close();?>
				</td>
			</tr>
			<tr>
				<td class="th">새로운 패키지 추가</td>
				<td>
						<?php echo NForm::open(NULL, FALSE, "create");?>
							<?php echo NForm::mode('create')?>
								<select name="map[package_filename][]">
									<option value="admin">
										관리자(1-admin)
									</option>
									<option value="users">
										사용자(2-users)
									</option>
								</select>.
								<select name="map[package_filename][]">
									<?php foreach($packages_key_all['res'] as $key=>$val):?>
									<option value="<?=$val['packages_key']?>">
										<?=$val['packages_name']?>(<?=$val['puid']?>-<?=$val['packages_key']?>)
									</option>
									<?php endforeach;?>
								</select>.

								<input type="text" name="map[package_filename][]" value="" class="inp"  onfocus="$(this).alphanumeric({allow:'_'})" style="ime-mode:inactive;" />
								<span class="cbtn_s" onclick="$('#formx_create').submit();" >추가</span>
						<?php echo NForm::close();?>
				</td>
			</tr>
		</table>
<?php
	# HTML END
	echo $tplt->tiles_admin_footer();
	echo $tplt->page_destruct_javascript();
	include_once( '../endproc.php' );
	echo $html->html_footer();
?>